package cn.jinhaze.service.impl;

import cn.jinhaze.common.pojo.entity.Dish;
import cn.jinhaze.common.pojo.entity.OrderDetail;
import cn.jinhaze.common.pojo.vo.DishVO;
import cn.jinhaze.mapper.OrderDetailMapper;
import cn.jinhaze.service.OrderDetailService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: L29
 * @create: 2024-12-25 13:18
 * @Version 1.0
 */
@Service
public class OrderDetailServiceImpl implements OrderDetailService {

	@Autowired
	private OrderDetailMapper orderDetailMapper;
	@Override
	public void save(OrderDetail orderDetail) {
		orderDetailMapper.insert(orderDetail);
	}

	@Override
	public List<DishVO> listByOrderId(String orderNo) {
		List<DishVO> dishVOList = new ArrayList<>();
		List<OrderDetail> orderDetailList
				= orderDetailMapper.selectList(new LambdaQueryWrapper<>(OrderDetail.class).eq(OrderDetail::getOrderId, orderNo));
		for (OrderDetail orderDetail : orderDetailList) {
			DishVO dishVO = new DishVO();
			dishVO.setId(orderDetail.getDishId());
			dishVO.setName(orderDetail.getName());
			dishVO.setImage(orderDetail.getImage());
			dishVO.setPrice(orderDetail.getAmount());
			dishVOList.add(dishVO);
		}
		return dishVOList;
	}
}